import { defineStore } from 'pinia';
import service from '/@/utils/request';
import { easyDate } from '/@/utils/formatTime';
import { query } from '/@/utils/params';
export interface Equipmentmode {
	id?: number;
	name: string;
	createdAt?: string;
}

export const useEquipmentmode = defineStore('equipmentmode', {
	state: () => ({
		equipmentmodeList: [],
	}),
	actions: {
		getEquipmentmodeList(name: string) {
			return service.get(query('/api/equipmentmode', { name })).then((res) => {
				return res.data.list.map((c: Equipmentmode) => {
					return {
						...c,
						createdAt: easyDate(c.createdAt!),
					};
				});
			});
		},
		addEquipmentmode(data: Equipmentmode) {
			return service.post('/api/equipmentmode', data);
		},
		updateEquipmentmode(data: Equipmentmode) {
			return service.patch('/api/equipmentmode/' + data.id, data);
		},
		deleteEquipmentmode(id: string) {
			return service.delete('/api/equipmentmode/' + id);
		},
	},
});
